package com.community.backend.mapper;

import com.community.backend.annotation.AutoFill;
import com.community.backend.enumeration.OperationType;
import com.community.backend.pojo.ShareFee;
import com.community.backend.pojo.vo.ShareFeeQueryVO;
import com.community.backend.pojo.dto.ShareFeeQueryDTO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Map;

@Mapper
public interface ShareFeeMapper {
    Page<ShareFeeQueryVO> pageQuery(ShareFeeQueryDTO shareFeeQueryDTO);
    @AutoFill(OperationType.INSERT)
    void insert(ShareFee shareFee);
    @AutoFill(OperationType.UPDATE)
    void update(ShareFee shareFee);

    @Select("select * from sharefee where id=#{id} and isDelete = '未删除'")
    ShareFee selectById(String id);
    @Update("update sharefee set tradeNo=#{tradeNo},payment=#{payment},buyerId=#{buyerId},gmtPayment=#{gmtPayment},status=#{status},updateId = '支付宝',updateName='支付宝',updateRole='支付宝',updateTime =#{gmtPayment} where id = #{outTradeNo}")
    void updatePayment(String outTradeNo, String tradeNo, String payment, String buyerId, String gmtPayment, String status);
    @Update("update sharefee set status= #{status},updateId = '支付宝',updateName='支付宝',updateRole='支付宝',updateTime =#{now} where id = #{outTradeNo}")
    void updateStatus(String outTradeNo, String status, LocalDateTime now);

    BigDecimal paidSumByMap(Map map);
    @AutoFill(OperationType.UPDATE)
    void updateById(ShareFee shareFee);
    @Select("select count(*) from sharefee where status = #{status} and isDelete = '未删除'")
    Integer selectAllByStatus(String status);
}
